package com.neuedu.util;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.neuedu.pojo.User;

import java.time.ZoneOffset;

public class JWTUtil {
    public static final String KEY = "User";
    public static final String PERMISSION_KEY = "Permission";
    public static final String SECURITYCODE_KEY="SecurityCode";

    public static String create(User user) {
        return JWT.create()
                .withClaim("username", user.getUsername())
                .withClaim("password", user.getPassword())
                .withClaim("id", user.getId())
                .withClaim("timestamp", user.getLastLogin().toInstant(ZoneOffset.of("+8")).toEpochMilli())
                .sign(Algorithm.HMAC256(KEY));
    }
}
